package com.liwenfeng.diancanspringboot.mapper;

import com.liwenfeng.diancanspringboot.pojo.dto.StatementChangePlaceDTO;
import com.liwenfeng.diancanspringboot.pojo.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {
    // 查询购物车
    List<ShoppingCart> list(ShoppingCart shoppingCart);

    // 修改购物车 todo 需要修改修改条件，按place修改,参数应为place=#{place}
    @Update("update shopping_cart set number = #{number},selected=1 where id = #{id}")
    void updateNumberById(Integer number, Long id);

    @Insert("insert into shopping_cart (name, image, dish_id, setmeal_id, dish_flavor, number, amount, user_id,place,create_time,selected,turnover_id) " +
            "values (#{name}, #{image}, #{dishId}, #{setmealId}, #{dishFlavor}, #{number}, #{amount}, #{userId}, #{place},now(),#{selected},#{turnoverId})")
    void insert(ShoppingCart shoppingCart);

    // 清空购物车 todo 需要修改删除条件，按place删除
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void deleteByUserId(Long userId);

    // 按id删除购物车
    @Delete("delete from shopping_cart where id = #{id}")
    void deleteById(Long id);

    /**
     * 批量插入购物车数据
     *
     * @param shoppingCartList
     */
    void insertBatch(List<ShoppingCart> shoppingCartList);

    /**
     * 根据place查询购物车
     *
     * @param shoppingCart
     * @return
     */
    @Select("select * from shopping_cart where place = #{place}")
    List<ShoppingCart> listbyPlace(ShoppingCart shoppingCart);

    // 清空购物车,重置id自增值（DDL)
    @Update("TRUNCATE TABLE shopping_cart")
    void cleanAll();

    @Update("update shopping_cart set place = #{toPlace} where place = #{fromPlace}")
    void updatePlace(StatementChangePlaceDTO statementChangePlaceDTO);

    @Select("select * from shopping_cart where id = #{id}")
    ShoppingCart getById(Long id);

    void updateById(ShoppingCart shoppingCart);

    void updateByIds(List<Long> ids, Integer selected);

    @Delete("delete from shopping_cart where turnover_id = #{turnoverId}")
    void deleteByturnoverId(Long turnoverId);
}
